package com.day18.ex06;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class ArrayListToFileDemo {
    public static void main(String[] args)throws IOException {
        ArrayList<Student>array=new ArrayList<Student>();
        Student s1=new Student("1001","张三",20,"北京");
        Student s2=new Student("1002","李四",21,"上海");
        Student s3=new Student("1003","王五",22,"广州");
        array.add(s1);
        array.add(s2);
        array.add(s3);
        BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\a.txt"));
        for(Student s:array){
            StringBuilder sb=new StringBuilder();
            sb.append(s.getSid()).append(",").append(s.getName()).append(",").append(s.getAge()).append(",").append(s.getAddress());
            bw.write(sb.toString());
            bw.newLine();
            bw.flush();

        }
        bw.close();
    }
}
